package com.shrct.businessprocess.budget.impl;

import com.google.common.base.Objects;
import com.shrct.businessprocess.budget.RCC3Budget;
import com.shrct.businessprocess.budget.RCC3BudgetType;
import com.shrct.businessprocess.budget.RCCostBreakDown;
import com.shrct.businessprocess.budget.impl.RCBudgetImpl;
import com.shrct.businessprocess.budget.proxy.RCC3BudgetProxy;
import com.shrct.businessprocess.project.RCProject;
import com.shrct.businessprocess.project.RCProjectMoney;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;

@Entity
@DiscriminatorValue("RCC3BUDGET_TYPE")
public class RCC3BudgetImpl extends RCBudgetImpl implements RCC3Budget {
  public RCC3BudgetImpl() {
    super();
  }
  
  public RCC3BudgetImpl(final RCCostBreakDown cbd) {
    super( cbd);
    
  }
  
  @Embedded
  @AttributeOverrides(value = { @AttributeOverride(name = "amount", column = @Column(name = "netPrice_amount") ), @AttributeOverride(name = "workaround", column = @Column(name = "netPrice_workaround") ) } )
  @AssociationOverrides(value = @AssociationOverride(name = "exchange", joinColumns = @JoinColumn(name = "netPrice_exchange") ) )
  private RCProjectMoney netPrice = com.shrct.businessprocess.project.RCProjectMoney.create();
  
  public RCProjectMoney getNetPrice() {
    return this.netPrice;
  }
  
  public RCC3Budget setNetPrice(final RCProjectMoney netPrice) {
    this.netPrice = netPrice;
    return this;			
    
  }
  
  private Double netTaxRate;
  
  public Double getNetTaxRate() {
    return this.netTaxRate;
  }
  
  public RCC3Budget setNetTaxRate(final Double netTaxRate) {
    this.netTaxRate = netTaxRate;
    return this;			
    
  }
  
  @Embedded
  @AttributeOverrides(value = { @AttributeOverride(name = "amount", column = @Column(name = "contractPrice_amount") ), @AttributeOverride(name = "workaround", column = @Column(name = "contractPrice_workaround") ) } )
  @AssociationOverrides(value = @AssociationOverride(name = "exchange", joinColumns = @JoinColumn(name = "contractPrice_exchange") ) )
  private RCProjectMoney contractPrice = com.shrct.businessprocess.project.RCProjectMoney.create();
  
  public RCProjectMoney getContractPrice() {
    return this.contractPrice;
  }
  
  public RCC3Budget setContractPrice(final RCProjectMoney contractPrice) {
    this.contractPrice = contractPrice;
    return this;			
    
  }
  
  private Double contractTaxRate;
  
  public Double getContractTaxRate() {
    return this.contractTaxRate;
  }
  
  public RCC3Budget setContractTaxRate(final Double contractTaxRate) {
    this.contractTaxRate = contractTaxRate;
    return this;			
    
  }
  
  private RCC3BudgetType type;
  
  public RCC3BudgetType getType() {
    return this.type;
  }
  
  public RCC3Budget setType(final RCC3BudgetType type) {
    this.type = type;
    return this;			
    
  }
  
  public String getTypeId() {
    return "RCC3Budget";
  }
  
  public String getEntityName() {
    String _switchResult = null;
    final RCC3BudgetType type = this.type;
    boolean _matched = false;
    if (!_matched) {
      if (Objects.equal(type,RCC3BudgetType.P0)) {
        _matched=true;
        _switchResult = "\u672A\u8BBE\u7F6E\u5DE5\u7A0B\u5E08\u670D\u52A1";
      }
    }
    if (!_matched) {
      if (Objects.equal(type,RCC3BudgetType.P3)) {
        _matched=true;
        _switchResult = "\u4E0D\u9700\u5DE5\u7A0B\u5E08\u670D\u52A1";
      }
    }
    if (!_matched) {
      if (Objects.equal(type,RCC3BudgetType.P4)) {
        _matched=true;
        _switchResult = "\u5B89\u88C5<=5\u4EBA\u5929\u6216\u5DE1\u68C0<=4\u6B21/\u5E74";
      }
    }
    if (!_matched) {
      if (Objects.equal(type,RCC3BudgetType.P5)) {
        _matched=true;
        _switchResult = "\u5B89\u88C5>5\u4EBA\u5929\u6216\u5DE1\u68C0>4\u6B21/\u5E74";
      }
    }
    if (!_matched) {
      if (Objects.equal(type,RCC3BudgetType.P6)) {
        _matched=true;
        _switchResult = "\u9700\u8981\u9A7B\u70B9\u670D\u52A1";
      }
    }
    return _switchResult;
  }
  
  public RCProjectMoney calcAdjustNetPrice() {
    RCProjectMoney _switchResult = null;
    final RCC3BudgetType type = this.type;
    boolean _matched = false;
    if (!_matched) {
      if (Objects.equal(type,RCC3BudgetType.P0)) {
        _matched=true;
        _switchResult = this.netPrice;
      }
    }
    if (!_matched) {
      if (Objects.equal(type,RCC3BudgetType.P3)) {
        _matched=true;
        _switchResult = this.netPrice;
      }
    }
    if (!_matched) {
      if (Objects.equal(type,RCC3BudgetType.P4)) {
        _matched=true;
        _switchResult = this.netPrice;
      }
    }
    if (!_matched) {
      if (Objects.equal(type,RCC3BudgetType.P5)) {
        _matched=true;
        RCProjectMoney _xifexpression = null;
        RCCostBreakDown _cbd = this.getCbd();
        RCProjectMoney _contractPrice = _cbd.getContractPrice();
        RCProjectMoney _multi = _contractPrice.multi(Double.valueOf(0.03));
        RCProjectMoney _substract = this.netPrice.substract(_multi);
        Double _amount = _substract.getAmount();
        boolean _greaterEqualsThan = ((_amount).doubleValue() >= 0);
        if (_greaterEqualsThan) {
          RCCostBreakDown _cbd_1 = this.getCbd();
          RCProjectMoney _contractPrice_1 = _cbd_1.getContractPrice();
          RCProjectMoney _multi_1 = _contractPrice_1.multi(Double.valueOf(0.03));
          RCProjectMoney _neg = _multi_1.neg();
          RCProjectMoney _plus = this.netPrice.plus(_neg);
          _xifexpression = _plus;
        } else {
          _xifexpression = this.netPrice;
        }
        _switchResult = _xifexpression;
      }
    }
    if (!_matched) {
      if (Objects.equal(type,RCC3BudgetType.P6)) {
        _matched=true;
        RCCostBreakDown _cbd_2 = this.getCbd();
        RCProject _project = _cbd_2.getProject();
        RCProjectMoney _zeroAmount = _project.getZeroAmount();
        _switchResult = _zeroAmount;
      }
    }
    return _switchResult;
  }
  
  public static RCC3Budget create(final RCCostBreakDown cbd, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.budget.RCC3Budget rCC3Budget = new com.shrct.businessprocess.budget.impl.RCC3BudgetImpl(
    	cbd
    );
    objectFactory.create(rCC3Budget);
    return rCC3Budget;			
    
  }
  
  public static RCC3Budget createRCC3BudgetImpl(final RCCostBreakDown cbd, final IObjectFactory objectFactory, final Procedure1<RCC3Budget> init) {
    com.shrct.businessprocess.budget.RCC3Budget rCC3Budget = new com.shrct.businessprocess.budget.impl.RCC3BudgetImpl(
    	cbd
    );
    objectFactory.create(rCC3Budget);
    init.apply(rCC3Budget);
    
    return rCC3Budget;			
    
  }
  
  public RCC3BudgetProxy toProxy() {
    com.shrct.businessprocess.budget.proxy.RCC3BudgetProxy proxy = new com.shrct.businessprocess.budget.proxy.RCC3BudgetProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
